INSTALL_DIR=/usr/local
CFLAGS=-Wall -O2
CC=gcc
obj-o = msgsrv.o msgcli.o msgdump.o # msgdsp
msgsrv-o = -Llibs/ -lmsgserv
msgcli-o =  -Llibs/ -lmsgserv -lpthread
msgdump-o =  -Llibs/ -lmsgserv
msgdsp-o = -lncurses -Llibs/ -lmsgserv

OBJECTS = $($(obj-o:.o=)-o)
LIBRARIES = $($(obj-o:.o=)-lib)
.SECONDARY:

all: libs $(obj-o)

$(obj-o): %.o: %.c
	$(CC) $(CFLAGS) $($(@:.o=)-o) $< -o $(@:.o=)

%.o: %.c %.h
	$(CC) $(CFLAGS) -c $< -o $@

libs:
	make -C libs/ all

install:
	install $(obj-o:.o=) $(INSTALL_DIR)/bin
	make -C libs/ $@


uninstall:
	cd $(INSTALL_DIR)/bin && rm -f $(obj) 
	make -C libs/ $@

clean:
	rm -f *.o || true
	make -C libs/ $@

distclean: clean
	rm $(obj-o) $($(obj-o:.o=)-o) || true
	make -C libs/ $@

.SUFFIXES:
	MAKEFLAGS += -r
.PHONY: install uninstall clean distclean libs

	
